/**
 * 系统导出通用方法
 * @param page_url 接口地址
 * @param filename 文件名称
 */
function downloadFile(page_url, filename) {
    var loading = layer.load(2, {
        shade: [0.6, '#000'], //0.4为透明度 ，#000 为颜色
        content: '正在加载，请勿继续操作...',
        success: function (layero) {
            layero.find('.layui-layer-content').css({
                'padding-top': '45px',
                'width': '200px',
                'background-position': 'top center',
                'color': '#fff',
                'margin-left': '15px',
                'text-align': 'center',
            });
        }
    });
    var req = new XMLHttpRequest();
    req.open("get", page_url, true);
    //监听进度事件
    req.addEventListener("progress", function (evt) {
        if (evt.lengthComputable) {
            var percentComplete = evt.loaded / evt.total;
            $("#progressing").html((percentComplete * 100) + "%");
        }
    }, false);
    req.responseType = "blob";
    req.onreadystatechange = function () {
        if (req.readyState === 4 && req.status === 200) {
            if (typeof window.chrome !== 'undefined') {
                // Chrome version
                var link = document.createElement('a');
                link.href = window.URL.createObjectURL(req.response);
                link.download = filename;
                link.click();
                layer.close(loading);
            } else if (typeof window.navigator.msSaveBlob !== 'undefined') {
                // IE version
                var blob = new Blob([req.response], {type: 'application/force-download'});
                window.navigator.msSaveBlob(blob, filename);
                layer.close(loading);
            } else {
                // Firefox version
                var file = new File([req.response], filename, {type: 'application/force-download'});
                window.open(URL.createObjectURL(file));
                layer.close(loading);
            }
        }
    };
    req.send();
}

/***
 * 日期大小判断
 * @param date1
 * @param date2
 * @returns {number}
 */
function compareDate(date1, date2) {
    var oDate1 = new Date(date1);
    var oDate2 = new Date(date2);
    if (oDate1.getTime() > oDate2.getTime()) {
        return 0;
    } else {
        return 1;
    }
}


//查询特殊贡献加分事项是否开启
function openOrClose(tbType) {
    $.ajax({
        url: rootPath + '/IndexMonthCheckController/selectMonth',
        type: 'post',
        data: {tbType: tbType},
        beforeSend: function () {
            this.layerIndex = layer.load(0, {shade: [0.5, '#393D49']});
        },
        success: function (result) {
            if (result.code == 200) {
                $("#open").hide();
                $("#close").show();
                $('#month').attr('disabled', 'disabled')
            } else {
                $("#open").show();
                $("#close").hide();
                $('#month').removeAttr('disabled')
            }
        },
        complete: function () {
            layer.close(this.layerIndex);
        },
    });
}
